import $ from "jquery";
import {url} from '../util/config'
import {message} from "antd";
import login from "./login";
function getNewLogin() {
    return loginOut()
}
export default function loginOut() {

    let token = localStorage.getItem("token")

    let status = null

    $.ajax({
        async:false,
        headers: {
            'Accept': "application/json",
            'Authorization': token
        },
        url: url.api_url+`Basic/LoginOut`,
        type: 'get',
        success: function (result) {
            status = result.result;
            if(status=="Token過期請重新登錄"){
                login(localStorage.getItem("account"), localStorage.getItem("password"));
                status = getNewLogin()
            }else {
                if(status=="ok"){
                    message.success("退登成功");
                }
            }
        },
        error:function (error) {
            status = "error";
        }
    })
    return status;

//  写ajax时把上面注释取消
//     return 'ok';
}
